﻿$(function() {
    ProdUpdate.init();
    Utils.textBoxsOnEnter(ProdUpdate._Save);
});


var ProdUpdate =
{
    init: function() {
        $("#btnSave").click(this._Save);
        $("#password").focus();
        $(document).keyup(function(e) {
            if (e.keyCode == 27) {
                window.parent.utility.closePopUpUrl();
            }
        });
    }
    , _Save: function() {
        var pwd = $("#password").val();
        var cwd = $("#conpassword").val();
        var sn = $("#sn").val();

        if (pwd.length === 0) {
            parent.utility.showPopUp(m.Err0012, 1, function() { $("#password").focus(); });
        }
        else if (cwd.length === 0) {
            parent.utility.showPopUp(m.Err0007, 1, function() { $("#conpassword").focus(); });
        }
        else if (cwd != pwd) {
            parent.utility.showPopUp(m.Err0013, 1, function() { $("#conpassword").val(''); $("#conpassword").focus(); });
        }
        else {
            var param = { sn: sn, password: pwd};
            var cb = function() { window.parent.location.reload(); };
            var ecb = function() { $("#oldpassword").val(''); $("#oldpassword").focus(); };
            window.parent.utility.ajaxext("BouService/Update", param, "POST", cb, ecb);
        }
    }
};